#ifndef HORZONTALTABBAR_H
#define HORZONTALTABBAR_H
#include <QWidget>
#include <QTabBar>
#include <QPainter>
#include <QStylePainter>
#include <QStyleOptionTabV3>
#include <QDebug>


class HorizontalTabBar : public QTabBar
{
public:
    explicit HorizontalTabBar(QWidget* parent=0) : QTabBar(parent)
    {
        setIconSize(QSize(80, 80));
    }

protected:
    QSize tabSizeHint(int) const
    {
        return QSize(100, 30);
    }
    void paintEvent(QPaintEvent *)
    {
        QStylePainter p(this);
        for (int index = 0; index <2; index++)
        {
            int x=5;
            qDebug()<< "init x:"<<&x;
        }
        QStyleOptionTabV3 tab;
        for (int index = 0; index < count(); index++)
        {

            initStyleOption(&tab, index);
            QIcon tempIcon = tab.icon;
            QString tempText = tab.text;
            tab.icon = QIcon();
            tab.text = QString();
            qDebug()<< "init after:"<<&tab;
            p.drawControl(QStyle::CE_TabBarTab, tab);//there is a problem
            QPainter painter;
            painter.begin(this);
            QRect tabrect = tabRect(index);
            tabrect.adjust(0, 8, 0, -8);
            painter.drawText(tabrect, Qt::AlignBottom | Qt::AlignHCenter, tempText);
            tempIcon.paint(&painter, 0, tabrect.top(), tab.iconSize.width(),
                           tab.iconSize.height(), Qt::AlignTop | Qt::AlignHCenter);
            painter.end();

        }
    }
};

#endif // HORZONTALTABBAR_H
